import cv2
import numpy as np
import picture_frame

capture = cv2.VideoCapture('../worker-zone-detection.mp4')
pic_res=0
while(capture.isOpened()):
    ret, frame = capture.read()
    if ret == True:
        if pic_res==0:
            cv2.imshow('frame', frame)
            if cv2.waitKey(40) & 0xFF == ord('q'):    #点击视频窗口，按q键选定图片
                pic_res =1
                frame_res=frame
                capture.release()
                break 
    else :
        capture.release()
        break
img=frame_res
(a,b)=picture_frame.get_rect(img,title='get_rect') 
frame_res = frame_res[a[1]:b[1],a[0]:b[0]]
frame_res = cv2.copyMakeBorder(frame_res, 640-(b[0]-a[0])//2, 640-(b[0]-a[0])//2, 960-(b[1]-a[1])//2, 960-(b[1]-a[1])//2, cv2.BORDER_CONSTANT, value=(0, 0, 0))
cv2.imwrite("../1.jpg", frame_res)           
cv2.destroyAllWindows() 

